/*
 * @(#)ListOnlineUserAction.java
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.framework.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionMapping;

import com.dcivision.framework.ApplicationContainer;
import com.dcivision.framework.ApplicationException;
import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SystemFunctionConstant;
import com.dcivision.framework.TextUtility;

/**
 * <p>Class Name:       ListOnlineUserAction.java    </p>
 * <p>Description:      The list action class for ListAuditLoginOut.jsp</p>
 *
 *    @author           Phoebe Wong
 *    @company          DCIVision Limited
 *    @creation date    31/07/2003
 *    @version          $Revision: 1.6 $
 */

public class ListOnlineUserAction extends AbstractListAction {

  public static final String REVISION = "$Revision: 1.6 $";


  /**
   *  Constructor - Creates a new instance of ListOnlineUserAction and define the default listName.
   */
  public ListOnlineUserAction() {
    super();
    this.setListName("onlineUserList");
  }

  /**
   * getMajorDAOClassName
   *
   * @return  The class name of the major DAObject will be used in this action.
   */
  public String getMajorDAOClassName() {
    return(null);
    //return("com.dcivision.framework.dao.AuditLoginOutDAObject");
  }

  /**
   * getFunctionCode
   *
   * @return  The corresponding system function code of action.
   */
  public String getFunctionCode() {
    return(SystemFunctionConstant.LOG_ONLINE_USER);
  }

  /**
   *  getListData
   *
   *  @param      mapping               ActionMapping from struts
   *  @param      form                  ActionForm from struts
   *  @param      request               HttpServletReuqest
   *  @param      respond               HttpServletRespond
   *  @return     void
   *  @throws     ApplicationException
   */
  public void getListData(ActionMapping mapping, AbstractSearchForm form, HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
    ApplicationContainer appCon = (ApplicationContainer)request.getSession().getServletContext().getAttribute(GlobalConstant.APPLICATION_CONTAINER_KEY);
    List resultList = appCon.getCurrentLoginUserList();
    int startOffset = TextUtility.parseInteger(form.getCurStartRowNo());
    int pageSize = TextUtility.parseInteger(form.getPageOffset());
    int rowLoopCnt = 0;
     
    request.setAttribute(this.m_sListName, new ArrayList(resultList.subList(startOffset-1,(startOffset-1+pageSize)>resultList.size()?resultList.size():(startOffset-1+pageSize))));
  }

}
